package logic

import (
	"context"
	"taobao-merchandise/merchandiserpc/merchandiserpc"

	"taobao-merchandise/api/internal/svc"
	"taobao-merchandise/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopUpdateLogic) ShopUpdate(req *types.ShopUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.MerchandiseRpc.ShopUpdate(l.ctx, &merchandiserpc.ShopUpdateRequest{
		ShopId: req.ShopId,
		Title:  req.Title,
		Image:  req.Image,
		Price:  float32(req.Price),
		UserId: req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Data:    update,
		Code:    200,
	}, nil
}
